package com.qf.servlet;

import com.qf.entity.StuInfo;
import com.qf.service.Impl.UserServiceImpl;
import com.qf.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author a1275872671
 * @version v1.0
 * @project guanqipeng
 * @package com.qf.servlet
 * @company
 * @date 2024/4/30 09:27
 */
@WebServlet(urlPatterns = "/LogServlet")
public class LogServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String shuno = request.getParameter("shuno");
        String pwd = request.getParameter("pwd");
        if (shuno==null||shuno.trim().equals("")){
            response.getWriter().write("用户名为空");
        }
        if (pwd==null||shuno.trim().equals("")){
            response.getWriter().write("密码为空");
        }
        UserService shulnfo=new UserServiceImpl();
        try {
            StuInfo login = shulnfo.Login(shuno, pwd);
            HttpSession session = request.getSession();
            session.setAttribute("login",login);
            response.sendRedirect("stulnfo.jsp");
        } catch (Exception e) {
            e.printStackTrace();
            response.sendRedirect("login.html");
        }


    }
}
